using System;
using System.Collections;
using System.Web.UI;

namespace Sedna.Core.Controller.Configurations
{
	public class ExceptionCode2FieldNameTranslator : IDataTranslator
	{
		private string defaultKey;
		private string prefix;

		public string DefaultKey
		{
			set { defaultKey = value; }
		}

		public string Prefix
		{
			set { prefix = value; }
		}


		public object Translate(Control control, object value)
		{
			return Translate(control, value, null);
		}


		public object Translate(Control control, object value, Type targetType)
		{
			try
			{
				int code = value is Int32?(int)value:Int32.Parse((string)value);
				return prefix + "." + SednaExceptionCodes.Code2Field(code);
			}
			catch
			{
				return defaultKey;
			}
		}
	}
}
